package net.neptech.service.impl;

import net.neptech.model.information.InforArticle;
import net.neptech.model.information.InforNews;
import net.neptech.repository.InforNewsRepository;
import net.neptech.service.InforNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Author 谢辉
 * @Date 2025/8/21 11:43
 * @Description TODO
 **/
@Service
public class InforNewsServiceImpl implements InforNewsService {

    @Autowired
    InforNewsRepository inforNewsRepository;
    @Override
    public void addInforNews(InforNews inforNews) {
        inforNews.setPublishTime(new Date());
        inforNewsRepository.save(inforNews);
    }

    @Override
    public void deleteInforNews(Long id) {
        //根据id查到文章
        InforNews inforNews = inforNewsRepository.findById(id).get();
        //修改文章状态
        inforNews.setStatus(0);
        //保存
        inforNewsRepository.save(inforNews);
    }

    @Override
    public List<InforNews> findInforNews() {
        return inforNewsRepository.findAllByStatus(1);
    }

    @Override
    public void updateInforNews(InforNews inforNews) {
        inforNews.setPublishTime(new Date());
        inforNewsRepository.save(inforNews);
    }

    @Override
    public InforNews findInforNewsById(Long id) {
        return inforNewsRepository.findById(id).get();
    }
}
